﻿using System.Threading;
using System.Windows.Forms;

namespace AutoUpdater
{
    public partial class ErrorView : Form
    {
        private static ErrorView _main;
        public ErrorView()
        {
            InitializeComponent();
            _main = this;
        }

        public static ErrorView CurrentInstance()
        {
            if (_main == null || _main.IsDisposed)
            {
                _main = null;
                _main = new ErrorView();
            }
            _main.StartPosition = FormStartPosition.CenterScreen;
            _main.BringToFront();
            _main.Show();
            return _main;
        }

        public static ErrorView AppendText(string msg)
        {
            CurrentInstance();
            if (_main.IsHandleCreated && _main.IsDisposed == false)
            {
                _main.txt_InfoLog.BeginInvoke(new ThreadStart(() =>
                    {
                        _main.txt_InfoLog.AppendText(msg);
                    }));
            }
            return _main;
        }
        public static ErrorView ShowText(string msg)
        {
            CurrentInstance();
            if (_main.IsHandleCreated && _main.IsDisposed == false)
            {
                _main.txt_InfoLog.BeginInvoke(new ThreadStart(() =>
                {
                    _main.txt_InfoLog.Text = msg;
                }));
            }
            return _main;
        }
    }
}
